const {User} = require('../../model/user');
const bcrypt = require('bcrypt');
module.exports = async (req, res, next) => {
	const {username, email, parssword, role, state} = req.body;
	const id = req.query.id;
	let user = await User.findOne({_id: id});
	const isValid = await bcrypt.compare(parssword, user.parssword);
	if(isValid) {
        await User.updateOne({_id: req.query.id}, {
        	username: username,
        	email: email,
        	role: role,
        	state: state
        });
        res.redirect('/admin/user');
	}else {
		let obj = {path: '/admin/user-edit', message: '密码比对失败 不能修改', id: req.query.id};
		next(JSON.stringify(obj));
	}
}